import java.util.Iterator;
import java.util.LinkedList;

public class MyHashMap {
    class Set {
        private int key;
        private int val;

        public Set(int key, int val) {
            this.key = key;
            this.val = val;
        }
        public int getKey() {
            return key;
        }

        public int getVal() {
            return val;
        }

        public void setVal(int val) {
            this.val = val;
        }
    }
        private static final int base = 769;
        private LinkedList[] list;
        public MyHashMap() {
            list = new LinkedList[base];
            for (int i = 0; i < base; i++) {
                list[i] = new LinkedList<Set>();
            }
        }

        public void put(int key, int value) {
            int h = hash(key);
            Iterator<Set> iterator = list[h].iterator();
            while (iterator.hasNext()){
                Set elem = iterator.next();
                if (elem.getKey() == key){
                    elem.setVal(value);
                    return;
                }
            }
            list[h].offerLast(new Set(key, value));
        }
        public int get(int key) {
            int h = hash(key);
            Iterator<Set> iterator = list[h].iterator();
            while (iterator.hasNext()){
                Set elem = iterator.next();
                if (elem.getKey() == key){
                    return elem.val;
                }
            }
            return -1;
        }
        public void remove(int key) {
            int h = hash(key);
            Iterator<Set> iterator = list[h].iterator();
            while (iterator.hasNext()){
                Set elem = iterator.next();
                if (elem.key == key){
                    list[h].remove(elem);
                    return;
                }
            }
        }

        public static int hash(int key){
        return key % base;
    }
}
